﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Client;
using System.Net;
using System.Runtime.Serialization.Json;

namespace Calendar
{
    public class GooglePlaces
    {
        public static GPlaces Search(GeoResponse what)
        {
            string url = string.Format(
                "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={0},{1}&radius=500&types=church&key=AIzaSyAxJi4QFlYeW5rM-acjZQ5KzNuC3H3PBKk&sensor=false",
                what.Results[0].Geometry.Location.Lat, what.Results[0].Geometry.Location.Lng);
            var request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GPlaces));
            var res = (GPlaces)serializer.ReadObject(request.GetResponse().GetResponseStream());
            return res;

        }

    }
}
